__doc__ =   """ Utility functions to check for various properties of structures.
            """

from EntityMisc import einput

def check_xray(structure):
    """ Check if the experiment type method has been parsed correctly from pdb header,
        and if it is an XRAY structure.
    """
    if structure.header.get('experiment_type')[0:5] not in ('X-RAY', 'SYNCH'):
        return False
    return True

def check_lenght(structure):
    a = einput(structure, 'A')
    if len(a) < 40:
        return False
    return True

def check_bbone(structure):
    c = einput(structure, 'C')
    for chain in c:
        for residue in chain.sorted_values()[1:-1]:
            if not residue.check_complete()[0]:
                return False
    return True

def check_schain(structure):
    r = einput(structure, 'R')
    for residue in r:
        if not residue.check_complete()[1]:
            return False
    return True

def check_unk(structure):
    """ No UNK or XAA residues.
    """
    r = einput(structure, 'R')
    if  r._select_children('UNK', 'eq', 'name') or\
        r._select_children('XAA', 'eq', 'name'):
        return False
    return True

def check_space(structure):
    if not structure.header.get('space_group'):
        return False
    return True

def check_resolution(structure, cutoff =3.0):
    if float((structure.header.get('resolution') or 10)) > cutoff:
        return False
    return True